#include <stdio.h>

// 1、引入头文件
#include "event_notifier.h"

#define MAX_NOTIFIER_CNT 20
#define EVENT_DEMO       0

// 2、定义处理函数
void* demo_event_callback(void* arg)
{
    printf("   [%s]%x\n", __func__, *((int*)arg));
    return NULL;
}

int main(int argc, char *argv[])
{
    int ret;
    int a = 0xa;
    int b = 0xb;
	// 3、声明事件通知器实例
    struct notifier_node notifier_head[MAX_NOTIFIER_CNT] = {0};

    ret = event_notifier_init(notifier_head, MAX_NOTIFIER_CNT);

    ret = event_notifier_get_size();
    printf("register_event max size is %d\n", ret);

	// 4、注册
    ret = event_notifier_register_event(EVENT_DEMO, demo_event_callback, &a);
    printf("register_event ret is %d\n", ret);
    // （重设优先级）
    ret = event_notifier_register_event_with_priority(EVENT_DEMO, 1,
                                                      demo_event_callback, &a);
    printf("register_event ret is %d\n", ret);

    // 注册事件，并指定优先级
    ret = event_notifier_register_event_with_priority(EVENT_DEMO, 2,
                                                      demo_event_callback, &a);

    // 获取当前注册的事件数量
    ret = event_notifier_get_cur_event_cnt();
    printf("register_event cnt is %d\n", ret);

	// 5、通知
    ret = event_notify(0);
    printf("event_notify called %d event_fun\n", ret);

	// 6、反注册
    ret =  event_notifier_unregister_event(EVENT_DEMO, demo_event_callback, &a);
    printf("unregister_event ret is %d\n", ret);

    ret = event_notifier_get_cur_event_cnt();
    printf("register_event cnt is %d\n", ret);

    ret = event_notify(0);
    printf("event_notify called %d event_fun\n", ret);

    ret = event_notifier_init(notifier_head, MAX_NOTIFIER_CNT);
    ret = event_notify(0);
    printf("event_notify called %d event_fun\n", ret);

    ret =  event_notifier_unregister_event(EVENT_DEMO, demo_event_callback, &b);
    printf("unregister_event ret is %d\n", ret);

    return 0;
}
